package com.xyy.yueshijia.utils;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.xyy.yueshijia.bean.shop.StoreBannerBean;
import com.xyy.yueshijia.bean.shop.StoreBean;
import com.xyy.yueshijia.bean.shop.StoreChannelBean;
import com.xyy.yueshijia.bean.shop.StoreDatasBean;
import com.xyy.yueshijia.bean.shop.StoreQueryBean;
import com.xyy.yueshijia.bean.shop.StoreTag_ClassifyBean;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.List;

/**
 * Created by lxs on 2016/11/25.
 */

public class JSonUtils {
    //解析首页数据
//    public static HomeBean parserHomeJson(String jsonString) {
//        try {
//
//            JSONObject obj = new JSONObject(jsonString);
//
//            HomeBean homeBean = JSON.parseObject(jsonString, HomeBean.class);
//
//            List<HomeBanner> homeBanners = homeBean.getDatas().getHomeBanners();
//
//            List<HomeDataType> homeDataTypes = homeBean.getDatas().getHomeDataTypes();
//
//            String banner_font = homeBean.getDatas().getBanner_font();
//
//            return homeBean;
//
//        } catch (JSONException e) {
//            Log.i("tag", "--异常-->" + e.getMessage());
//            e.printStackTrace();
//        }
//
//        return null;
//    }

    public static StoreBean getStoreData(String jsoString) {

        try {

            StoreBean shopBean = JSON.parseObject(jsoString, StoreBean.class);

            StoreDatasBean shopDatas = new StoreDatasBean();

            JSONObject obj = new JSONObject(jsoString);

            JSONObject obj1 = obj.optJSONObject("datas");

            JSONArray query = obj1.optJSONArray("query");

            List<StoreQueryBean> shopQueryBeen = JSON.parseArray(query.toString(), StoreQueryBean.class);
            //
            shopDatas.setStoreQueryBean(shopQueryBeen);

            JSONArray obj2 = obj1.optJSONArray("banner");

            List<StoreBannerBean> shopBannerBeen = JSON.parseArray(obj2.toString(), StoreBannerBean.class);
            //
            shopDatas.setStoreBannerBean(shopBannerBeen);
            //
            JSONArray tag_classify = obj1.optJSONArray("tag_classify");

            List<StoreTag_ClassifyBean> shopTagBeen = JSON.parseArray(tag_classify.toString(), StoreTag_ClassifyBean.class);

            shopDatas.setStoreTag_classifyBean(shopTagBeen);
            JSONObject channel = obj1.optJSONObject("channel");

            StoreChannelBean shopChannel = JSON.parseObject(channel.toString(), StoreChannelBean.class);

            shopDatas.setStoreChannelBean(shopChannel);

            shopBean.setStoreDatasBean(shopDatas);
            return shopBean;

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

}
